var e = getApp(), t = require("../../utils/city.js");

Page({
    data: {
        provinceArray: [],
        cityArray: [ "全国" ],
        cityData: [ [ "全国" ], [ "全国" ] ],
        citySelectIndex: [ 0, 0 ],
        province: "四川省",
        city: "成都市",
        pageNo: 1,
        pageSize: 10,
        role: e.role.zhuchi,
        currentRoleTab: 0,
        hotUserTitle: "",
        currentUserTab: 0,
        resultUserTitle1: "",
        resultUserTitle2: "",
        resultUserTitle3: "",
        resultUserTitle2Key: "",
        resultUserTitle3Key: "",
        hotUserMore: 0,
        hotUsers1: [],
        hotUsers2: [],
        hotUsers3: [],
        teamTabHeight: 0,
        teamItemHeight: 170,
        currentTeamTab: 0,
        resultTeamTitle1: "",
        resultTeamTitle2: "",
        resultTeamTitle3: "",
        resultTeamTitle2Key: "",
        resultTeamTitle3Key: "",
        teamMore: 0,
        teams1: [],
        teams2: [],
        teams3: [],
        workHeight: 0,
        recommendDynamics: [],
        recommendDynamicMore: 0,
        dynamics: [],
        adData: [ {
            image: "https://i.hunyu.co/upload/advert/advert27.jpg",
            url: "https://www.hunyu.co/appweb/scheduleHotDay.do"
        } ]
    },
    onLoad: function(a) {
        var r = t.cityList.provinces.map(function(e, t, a) {
            return e.name;
        });
        this.setData({
            hotUserTitle: e.util.getRoleName(this.data.role),
            provinceArray: r,
            cityData: [ r, [ "全国" ] ]
        });
        var s = wx.getStorageSync(e.storage.userInfo).info;
        if (console.log(s), null != s) {
            var i = s.province, n = s.city;
            this.setData({
                city: n,
                province: i
            });
        }
        this.loadData(!0), this.loadAdData();
    },
    bindMultiPickerChange: function(e) {
        this.setData({
            hotUsers1: [],
            hotUsers2: [],
            hotUsers3: [],
            currentUserTab: 0,
            currentTeamTab: 0,
            teams1: [],
            teams2: [],
            teams3: []
        }), console.log("citySelectIndex", this.data.citySelectIndex[0]), 0 == this.data.citySelectIndex[0] && this.setData({
            province: "全国",
            city: "全国"
        }), this.loadData(!0);
    },
    bindMultiPickerColumnChange: function(e) {
        if (console.log("修改的列为", e.detail.column, "，值为", e.detail.value), 0 == e.detail.column) {
            var a = t.cityList.provinces[e.detail.value].citys.map(function(e, t, a) {
                return e.name;
            }), r = a[0], s = this.data.provinceArray[e.detail.value], i = [ e.detail.value, 0 ];
            this.setData({
                cityData: [ this.data.provinceArray, a ],
                cityArray: a,
                province: s,
                city: r,
                citySelectIndex: i
            });
        } else {
            r = this.data.cityArray[e.detail.value];
            console.log(this.data.province, r), this.setData({
                city: r
            });
        }
    },
    loadAdData: function() {
        var t = this;
        e.network.post({
            url: e.url.listAdvert,
            params: {},
            success: function(e) {
                var a = e.data.data.adverts;
                1 == e.data.result && t.setData({
                    adData: a
                });
            }
        });
    },
    loadData: function(t) {
        var a = this, r = a.data.pageNo;
        t ? r = 1 : r += 1, e.network.post({
            url: e.url.searchScheduleData,
            params: {
                province: a.data.province,
                city: a.data.city,
                role: a.data.role,
                pageNo: r,
                pageSize: 10
            },
            before: function() {
                wx.showNavigationBarLoading(), wx.showLoading({
                    title: "加载中"
                });
            },
            success: function(t) {
                wx.hideLoading(), a.data.role == e.role.zhuchi && 1 == r && wx.setStorageSync(e.storage.searchScheduleData, t.data), 
                a.setData({
                    pageNo: r
                }), a.handleData(t.data);
            },
            fail: function() {
                wx.hideLoading(), e.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    handleData: function(t) {
        var a = this;
        if (1 == t.result) if (1 == a.data.pageNo) a.setData({
            resultUserTitle1: t.data.resultUserTitle1,
            resultUserTitle2: t.data.resultUserTitle2,
            resultUserTitle3: t.data.resultUserTitle3,
            resultUserTitle2Key: t.data.resultUserTitle2Key,
            resultUserTitle3Key: t.data.resultUserTitle3Key,
            hotUserMore: t.data.hotUserMore,
            hotUsers1: t.data.hotUsers,
            resultTeamTitle1: t.data.resultTeamTitle1,
            resultTeamTitle2: t.data.resultTeamTitle2,
            resultTeamTitle3: t.data.resultTeamTitle3,
            resultTeamTitle2Key: t.data.resultTeamTitle2Key,
            resultTeamTitle3Key: t.data.resultTeamTitle3Key,
            teamMore: t.data.teamMore,
            teams1: t.data.teams,
            teamTabHeight: a.data.teamItemHeight * t.data.teams.length,
            workHeight: t.data.recommendDynamics.length > 2 ? 580 : 290,
            recommendDynamics: t.data.recommendDynamics,
            recommendDynamicMore: t.data.recommendDynamicMore,
            dynamics: t.data.dynamics
        }); else {
            var r = a.data.dynamics;
            r = r.concat(t.data.dynamics), a.setData({
                dynamics: r
            });
        } else e.util.showToast(t.message);
    },
    blidSearchByDateTap: function(e) {
        wx.navigateTo({
            url: "/pages/add/addOrder/addOrder"
        });
    },
    bindSearchTap: function(e) {
        wx.navigateTo({
            url: "/pages/searchSchedule/search/search"
        });
    },
    clickAd: function(e) {
        var t = e.currentTarget.dataset.url;
        console.log(t), wx.navigateTo({
            url: "../web/web?url=" + t
        });
    },
    bindRoleSwiperChange: function(e) {
        this.setData({
            currentRoleTab: e.detail.current
        });
    },
    bindRoleTap: function(t) {
        var a = this, r = t.currentTarget.dataset.role;
        a.setData({
            role: r,
            hotUserTitle: e.util.getRoleName(r),
            hotUsers1: [],
            hotUsers2: [],
            hotUsers3: [],
            currentUserTab: 0,
            currentTeamTab: 0,
            teams1: [],
            teams2: [],
            teams3: []
        }), a.loadData(!0);
    },
    bindAvatarTap: function(t) {
        var a = t.currentTarget.dataset.accesstoken;
        e.util.navToUserHome(a);
    },
    bindUserSwiperChange: function(t) {
        var a = this;
        a.setData({
            currentUserTab: t.detail.current
        }), (1 == a.data.currentUserTab && 0 == a.data.hotUsers2.length || 2 == a.data.currentUserTab && 0 == a.data.hotUsers3.length) && e.network.post({
            url: e.url.searchScheduleHotUser,
            params: {
                province: 1 == a.data.currentUserTab ? a.data.resultUserTitle2Key : a.data.resultUserTitle3Key,
                role: a.data.role
            },
            before: function() {
                wx.showLoading({
                    title: "获取数据"
                });
            },
            success: function(t) {
                1 == t.data.result ? 1 == a.data.currentUserTab ? a.setData({
                    hotUsers2: t.data.data.hotUsers
                }) : a.setData({
                    hotUsers3: t.data.data.hotUsers
                }) : e.util.showToast(t.data.message);
            },
            fail: function() {
                e.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    bindUserTabTap: function(e) {
        this.setData({
            currentUserTab: e.currentTarget.dataset.currenttab
        });
    },
    bindTeamUserTap: function(t) {
        var a = t.currentTarget.dataset.accesstoken;
        e.util.navToUserHome(a);
    },
    clickTeam: function(t) {
        var a = t.currentTarget.dataset.teamid;
        e.util.navToTeamHome(a);
    },
    setTabHeight: function() {
        var e = 0, t = this;
        0 == t.data.currentTeamTab ? e = t.data.teamItemHeight * t.data.teams1.length : 1 == t.data.currentTeamTab ? e = t.data.teamItemHeight * t.data.teams2.length : 2 == t.data.currentTeamTab && (e = t.data.teamItemHeight * t.data.teams3.length), 
        t.setData({
            teamTabHeight: e
        });
    },
    bindTeamSwiperChange: function(t) {
        var a = this;
        a.setData({
            currentTeamTab: t.detail.current
        }), a.setTabHeight(), (1 == a.data.currentTeamTab && 0 == a.data.teams2.length || 2 == a.data.currentTeamTab && 0 == a.data.teams3.length) && e.network.post({
            url: e.url.searchScheduleHotTeam,
            params: {
                province: 1 == a.data.currentTeamTab ? a.data.resultTeamTitle2Key : a.data.resultTeamTitle3Key,
                role: a.data.role
            },
            before: function() {
                wx.showLoading({
                    title: "获取数据"
                });
            },
            success: function(t) {
                1 == t.data.result ? (1 == a.data.currentTeamTab ? a.setData({
                    teams2: t.data.data.teams
                }) : a.setData({
                    teams3: t.data.data.teams
                }), a.setTabHeight()) : e.util.showToast(t.data.message);
            },
            fail: function() {
                e.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    bindTeamTabTap: function(e) {
        this.setData({
            currentTeamTab: e.currentTarget.dataset.currenttab
        });
    },
    onReady: function() {
        var t = wx.getStorageSync(e.storage.searchScheduleData);
        t && 1 == t.result && this.handleData(t);
    },
    onShow: function() {
        e.globalData.currentTab = "/pages/searchSchedule/searchSchedule", wx.showTabBar({});
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.loadData(!1);
    },
    onShareAppMessage: function() {
        var t = e.util.getShareInfo();
        return {
            title: e.globalData.commonShareTitle,
            path: t[0],
            imageUrl: t[1],
            success: function(e) {},
            fail: function(e) {}
        };
    }
});